﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySQLDriverCS;

namespace TJADRICD.CollaborativeDesignPlugin
{
   
    class MySQLUserRole
    {
        public string projectID;
        public string subProjectID;
        public string professionName;
        public string validation;
        public string audit;
        public string designManager1;
        public string designManager2;
        public string professionalPerson1;
        public string professionalPerson2;
        public string design1;
        public string design2;
        public string draw;
        public string proof;

    }
    class MySQLUserRoleDao
    {
        static String myConnstr = new MySQLConnectionString("localhost", "test", "root", "root").AsString;
        public List<MySQLUserRole> GetDrawingSignName(List<string> userIdList)
        {
            List<MySQLUserRole> userRoleList = new List<MySQLUserRole>();
            
            MySQLConnection myConn = new MySQLConnection(myConnstr);
            try
            {
                myConn.Open();
                MySQLCommand mscom = new MySQLCommand("set names gb2312", myConn);
                mscom.ExecuteNonQuery();
                for (int i = 0; i < userIdList.Count; ++i)
                {
                    string selectstr = "select * from userrole where VALIDATION = '" + userIdList[i] + "' OR AUDIT = '" + userIdList[i] + "' OR DESIGN_MANAGER1 = '" + userIdList[i] + "' OR DESIGN_MANAGER2 = '" + userIdList[i] + "' OR PROFESSIONAL_PERSON1 = '" + userIdList[i] + "' OR PROFESSIONAL_PERSON2 = '" + userIdList[i] + "' OR DESIGN1 = '" + userIdList[i] + "' OR DESIGN2 = '" + userIdList[i] + "' OR DRAW = '" +userIdList[i]+"' OR PROOF = '"+userIdList[i]+"'";
                    MySQLCommand myCom = new MySQLCommand(selectstr, myConn);
                    MySQLDataReader reader = myCom.ExecuteReaderEx();
                    try
                    {
                        while (reader.Read())
                        {
                            if (reader.HasRows)
                            {
                                MySQLUserRole userRole = new MySQLUserRole();
                                userRole.projectID = reader.GetString(1);
                                userRole.subProjectID = reader.GetString(2);
  
                                //byte[] proByteName = reader.GetValue(3);

                                userRole.professionName = reader.GetString(3);//System.Text.Encoding.UTF8.GetString();
                                userRole.validation = reader.GetString(4);
                                userRole.audit = reader.GetString(5);
                                userRole.designManager1 = reader.GetString(6);
                                userRole.designManager2 = reader.GetString(7);
                                userRole.professionalPerson1 = reader.GetString(8);
                                userRole.professionalPerson2 = reader.GetString(9);
                                userRole.design1 = reader.GetString(10);
                                userRole.design2 = reader.GetString(11);
                                userRole.draw = reader.GetString(12);
                                userRole.proof = reader.GetString(13);


                                userRoleList.Add(userRole);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    reader.Close();
                }

                myConn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(myConn);
            }
            return userRoleList;
        }
        bool userIdMatch(MySQLUserRole uRole, string userID)
        {
            if (uRole.validation == userID || uRole.audit == userID || uRole.designManager1 == userID || uRole.designManager2 == userID || uRole.professionalPerson1 == userID || uRole.professionalPerson2 == userID || uRole.designManager1 == userID || uRole.designManager2 == userID || uRole.design1 == userID || uRole.design2 == userID || uRole.draw == userID || uRole.proof == userID) return true;
            return false;
        }
        
    }
}
